//
// Created by hjie on 23-7-16.
//

#include "user_data_manager.h"

UserDataManager::UserDataManager(DataManager *data_manager)
{
    m_data_manager = data_manager;
}

UserDataManager::~UserDataManager()
{
    m_id_user_map.clear();
    printf("destructor %s.\n", __func__ );
}

bool UserDataManager::AddUser(const std::string &user_id)
{
    auto user = std::make_shared<UserData>(m_data_manager, user_id);
    m_id_user_map[user_id] = user;
    return true;
}

bool UserDataManager::RemoveUserById(const std::string &id)
{
    auto iter = m_id_user_map.find(id);
    if (iter != m_id_user_map.end())
    {
        m_id_user_map.erase(iter);
    }
    return true;
}

std::shared_ptr<UserData> UserDataManager::GetUserById(const std::string &id)
{
    auto iter = m_id_user_map.find(id);
    return iter == m_id_user_map.end() ? nullptr : iter->second;
}

int UserDataManager::GetUserSize()
{
    return m_id_user_map.size();
}

std::map<std::string, std::shared_ptr<UserData>> UserDataManager::GetUserMap()
{
    return m_id_user_map;
}